import React, { useState } from "react";
import Todolist from "./Todolist";
import { TodolistContext } from "./context";

const App = () => {
    const [isShow, setIsShow] = useState(true);
    const [list, setList] = useState([1, 2, 3, 4]);
    const upDateList = (val) => {
        setList([val, ...list]); //异步操作
        localStorage.setItem("todolist", JSON.stringify([val, ...list]));
    };

    return (
        <div className="App">
            <TodolistContext.Provider value={{ list, upDateList }}>
                <Todolist />
                <button onClick={() => setIsShow(!isShow)}>显示/隐藏</button>
            </TodolistContext.Provider>
        </div>
    );
};

export default App;
